package com.example.barrage.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.List;

/**
 * 敏感词过滤服务
 */
@Service
public class SensitiveWordService {

    private static final Logger logger = LoggerFactory.getLogger(SensitiveWordService.class);

    // 敏感词列表
    private static List<String> SENSITIVE_WORDS;

    @PostConstruct
    public void init() {
        // 初始化敏感词列表
        SENSITIVE_WORDS = Arrays.asList(
            "fuck", "shit", "damn", "傻逼", "笨蛋", "白痴", "sb", "nmsl"
        );
        logger.info("敏感词服务初始化完成，共加载 {} 个敏感词", SENSITIVE_WORDS.size());
    }

    /**
     * 检查内容是否包含敏感词
     * @param content 检查的内容
     * @return 是否包含敏感词
     */
    public boolean containsSensitiveWords(String content) {
        if (content == null || content.isEmpty()) {
            return false;
        }
        
        String lowerContent = content.toLowerCase();
        for (String word : SENSITIVE_WORDS) {
            if (lowerContent.contains(word.toLowerCase())) {
                logger.debug("在内容中发现敏感词: {}，内容: {}", word, content);
                return true;
            }
        }
        return false;
    }
}